package com.chengweiyi.security.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author xiao hu die
 * @Date 2022/5/13 16:52
 * @Version 1.0
 */
@Data

public class SecurityUser implements UserDetails {
    /**当前登录用户*/
    private transient User currentUserInfo;
    /**当前权限*/
    private List<String> permissionValueList;

    public SecurityUser() {
    }

    public SecurityUser(User currentUserInfo) {
       if (currentUserInfo!=null){
           this.currentUserInfo  = currentUserInfo;
       }
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
    Collection<GrantedAuthority> authorities =   new ArrayList<>();
        for (String s : permissionValueList) {
            if (StringUtils.isEmpty(s)) continue;
            SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(s);
            authorities.add(simpleGrantedAuthority);
        }
     return authorities;
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    public String getUsername() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
